/*
               File: CarneConversion
        Description: Conversion for table Carne
             Author: GeneXus C# Generator version 10_2_1-58381
       Generated on: 8/23/2012 22:28:26.94
       Program type: Callable routine
          Main DBMS: sqlserver
*/
using System;
using System.Collections;
using GeneXus.Utils;
using GeneXus.Resources;
using GeneXus.Application;
using GeneXus.Metadata;
using GeneXus.Reorg;
using System.Threading;
using GeneXus.Programs;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using GeneXus.Data;
using com.genexus;
using GeneXus.Data.ADO;
using GeneXus.Data.NTier;
using GeneXus.Data.NTier.ADO;
using System.Runtime.Remoting;
using GeneXus.WebControls;
using GeneXus.Http;
using GeneXus.Procedure;
using GeneXus.XML;
using GeneXus.Search;
using GeneXus.Encryption;
using GeneXus.Http.Client;
using System.Xml.Serialization;
using System.Data.SqlTypes;
namespace GeneXus.Programs {
   public class carneconversion : GXProcedure
   {
      public carneconversion( )
      {
         context = new GxContext(  );
         DataStoreUtil.LoadDataStores( context);
         dsDefault = context.GetDataStore("Default") ;
         IsMain = true;
      }

      public carneconversion( IGxContext context )
      {
         this.context = context;
         IsMain = false;
         dsDefault = context.GetDataStore("Default") ;
      }

      public void release( )
      {
      }

      public void execute( )
      {
         initialize();
         executePrivate();
      }

      public void executeSubmit( )
      {
         carneconversion objcarneconversion;
         objcarneconversion = new carneconversion();
         objcarneconversion.context.SetSubmitInitialConfig(context);
         objcarneconversion.initialize();
         ThreadPool.QueueUserWorkItem( new WaitCallback( executePrivateCatch ),objcarneconversion);
      }

      void executePrivateCatch( object stateInfo )
      {
         try
         {
            ((carneconversion)stateInfo).executePrivate();
         }
         catch ( Exception e )
         {
            GXUtil.SaveToEventLog( "Design", e);
            throw e ;
         }
      }

      void executePrivate( )
      {
         /* GeneXus formulas */
         /* Output device settings */
         cmdBuffer=" SET IDENTITY_INSERT [GXA0003] ON "
         ;
         RGZ = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault,0,true,false,null);
         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
         RGZ.ExecuteStmt() ;
         RGZ.Drop();
         /* Using cursor CARNECONVE2 */
         pr_default.execute(0);
         while ( (pr_default.getStatus(0) != 101) )
         {
            A9CarneNombre = CARNECONVE2_A9CarneNombre[0] ;
            A8CarneId = CARNECONVE2_A8CarneId[0] ;
            AV14GXV3 = 0 ;
            AV13GXV4 = "" ;
            AV12GXV5 = "" ;
            AV11GXV6 = 0 ;
            AV10GXV7 = false ;
            /* Using cursor CARNECONVE3 */
            pr_default.execute(1, new Object[] {A8CarneId});
            while ( (pr_default.getStatus(1) != 101) )
            {
               A7PeriodistaPremiado = CARNECONVE3_A7PeriodistaPremiado[0] ;
               A6PeriodistaSueldo = CARNECONVE3_A6PeriodistaSueldo[0] ;
               A5PeriodistaApellido = CARNECONVE3_A5PeriodistaApellido[0] ;
               A4PeriodistaNombre = CARNECONVE3_A4PeriodistaNombre[0] ;
               A3PeriodistaId = CARNECONVE3_A3PeriodistaId[0] ;
               AV14GXV3 = A3PeriodistaId ;
               AV13GXV4 = A4PeriodistaNombre ;
               AV12GXV5 = A5PeriodistaApellido ;
               AV11GXV6 = A6PeriodistaSueldo ;
               AV10GXV7 = A7PeriodistaPremiado ;
               /* Exit For each command. Update data (if necessary), close cursors & exit. */
               if (true) break;
               pr_default.readNext(1);
            }
            pr_default.close(1);
            /*
               INSERT RECORD ON TABLE GXA0003

            */
            AV2CarneId = A8CarneId ;
            if ( (0==AV14GXV3) )
            {
               AV3PeriodistaId = 0 ;
            }
            else
            {
               AV3PeriodistaId = AV14GXV3 ;
            }
            AV4CarneNombre = A9CarneNombre ;
            if ( String.IsNullOrEmpty(StringUtil.RTrim( AV13GXV4)) )
            {
               AV5PeriodistaNombre = " " ;
            }
            else
            {
               AV5PeriodistaNombre = AV13GXV4 ;
            }
            if ( String.IsNullOrEmpty(StringUtil.RTrim( AV12GXV5)) )
            {
               AV6PeriodistaApellido = " " ;
            }
            else
            {
               AV6PeriodistaApellido = AV12GXV5 ;
            }
            if ( (0==AV11GXV6) )
            {
               AV7PeriodistaSueldo = 0 ;
            }
            else
            {
               AV7PeriodistaSueldo = AV11GXV6 ;
            }
            if ( (false==AV10GXV7) )
            {
               AV8PeriodistaPremiado = false ;
            }
            else
            {
               AV8PeriodistaPremiado = AV10GXV7 ;
            }
            AV9PeriodistaMonto = 0 ;
            /* Using cursor CARNECONVE4 */
            pr_default.execute(2, new Object[] {AV2CarneId, AV3PeriodistaId, AV4CarneNombre, AV5PeriodistaNombre, AV6PeriodistaApellido, AV7PeriodistaSueldo, AV8PeriodistaPremiado, AV9PeriodistaMonto});
            pr_default.close(2);
            dsDefault.SmartCacheProvider.SetUpdated("GXA0003") ;
            if ( (pr_default.getStatus(2) == 1) )
            {
               context.Gx_err = 1 ;
               Gx_emsg = (String)(GXResourceManager.GetMessage("GXM_noupdate")) ;
            }
            else
            {
               context.Gx_err = 0 ;
               Gx_emsg = "" ;
            }
            /* End Insert */
            pr_default.readNext(0);
         }
         pr_default.close(0);
         cmdBuffer=" SET IDENTITY_INSERT [GXA0003] OFF "
         ;
         RGZ = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault,0,true,false,null);
         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
         RGZ.ExecuteStmt() ;
         RGZ.Drop();
         this.cleanup();
      }

      public void cleanup( )
      {
         CloseOpenCursors();
         if ( IsMain )
         {
            context.CloseConnections() ;
         }
         exitApplication();
      }

      protected void CloseOpenCursors( )
      {
      }

      public override void initialize( )
      {
         cmdBuffer = "" ;
         scmdbuf = "" ;
         CARNECONVE2_A9CarneNombre = new String[] {""} ;
         CARNECONVE2_A8CarneId = new short[1] ;
         A9CarneNombre = "" ;
         AV13GXV4 = "" ;
         AV12GXV5 = "" ;
         CARNECONVE3_A8CarneId = new short[1] ;
         CARNECONVE3_A7PeriodistaPremiado = new bool[] {false} ;
         CARNECONVE3_A6PeriodistaSueldo = new short[1] ;
         CARNECONVE3_A5PeriodistaApellido = new String[] {""} ;
         CARNECONVE3_A4PeriodistaNombre = new String[] {""} ;
         CARNECONVE3_A3PeriodistaId = new short[1] ;
         A5PeriodistaApellido = "" ;
         A4PeriodistaNombre = "" ;
         AV4CarneNombre = "" ;
         AV5PeriodistaNombre = "" ;
         AV6PeriodistaApellido = "" ;
         Gx_emsg = "" ;
         pr_default = new DataStoreProvider(context, new GeneXus.Programs.carneconversion__default(),
            new Object[][] {
                new Object[] {
               CARNECONVE2_A9CarneNombre, CARNECONVE2_A8CarneId
               }
               , new Object[] {
               CARNECONVE3_A8CarneId, CARNECONVE3_A7PeriodistaPremiado, CARNECONVE3_A6PeriodistaSueldo, CARNECONVE3_A5PeriodistaApellido, CARNECONVE3_A4PeriodistaNombre, CARNECONVE3_A3PeriodistaId
               }
               , new Object[] {
               }
            }
         );
         /* GeneXus formulas. */
         context.Gx_err = 0 ;
      }

      private short A8CarneId ;
      private short AV14GXV3 ;
      private short AV11GXV6 ;
      private short A6PeriodistaSueldo ;
      private short A3PeriodistaId ;
      private short AV2CarneId ;
      private short AV3PeriodistaId ;
      private short AV7PeriodistaSueldo ;
      private short AV9PeriodistaMonto ;
      private int GIGXA0003 ;
      private String cmdBuffer ;
      private String scmdbuf ;
      private String Gx_emsg ;
      private bool AV10GXV7 ;
      private bool A7PeriodistaPremiado ;
      private bool AV8PeriodistaPremiado ;
      private String A9CarneNombre ;
      private String AV13GXV4 ;
      private String AV12GXV5 ;
      private String A5PeriodistaApellido ;
      private String A4PeriodistaNombre ;
      private String AV4CarneNombre ;
      private String AV5PeriodistaNombre ;
      private String AV6PeriodistaApellido ;
      private IGxDataStore dsDefault ;
      private GxCommand RGZ ;
      private IDataStoreProvider pr_default ;
      private String[] CARNECONVE2_A9CarneNombre ;
      private short[] CARNECONVE2_A8CarneId ;
      private short[] CARNECONVE3_A8CarneId ;
      private bool[] CARNECONVE3_A7PeriodistaPremiado ;
      private short[] CARNECONVE3_A6PeriodistaSueldo ;
      private String[] CARNECONVE3_A5PeriodistaApellido ;
      private String[] CARNECONVE3_A4PeriodistaNombre ;
      private short[] CARNECONVE3_A3PeriodistaId ;
   }

   public class carneconversion__default : DataStoreHelperBase, IDataStoreHelper
   {
      public ICursor[] getCursors( )
      {
         cursorDefinitions();
         return new Cursor[] {
          new ForEachCursor(def[0])
         ,new ForEachCursor(def[1])
         ,new UpdateCursor(def[2])
       };
    }

    private static CursorDef[] def;
    private void cursorDefinitions( )
    {
       if ( def == null )
       {
          Object[] prmCARNECONVE2 ;
          prmCARNECONVE2 = new Object[] {
          } ;
          Object[] prmCARNECONVE3 ;
          prmCARNECONVE3 = new Object[] {
          new Object[] {"@CarneId",SqlDbType.SmallInt,4,0}
          } ;
          Object[] prmCARNECONVE4 ;
          prmCARNECONVE4 = new Object[] {
          new Object[] {"@AV2CarneId",SqlDbType.SmallInt,4,0} ,
          new Object[] {"@AV3PeriodistaId",SqlDbType.SmallInt,4,0} ,
          new Object[] {"@AV4CarneNombre",SqlDbType.VarChar,40,0} ,
          new Object[] {"@AV5PeriodistaNombre",SqlDbType.VarChar,40,0} ,
          new Object[] {"@AV6PeriodistaApellido",SqlDbType.VarChar,40,0} ,
          new Object[] {"@AV7PeriodistaSueldo",SqlDbType.SmallInt,4,0} ,
          new Object[] {"@AV8PeriodistaPremiado",SqlDbType.Bit,4,0} ,
          new Object[] {"@AV9PeriodistaMonto",SqlDbType.SmallInt,4,0}
          } ;
          def= new CursorDef[] {
              new CursorDef("CARNECONVE2", "SELECT [CarneNombre], [CarneId] FROM [Carne] ORDER BY [CarneId] ",false, GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK, false, this,prmCARNECONVE2,100,0,true,false )
             ,new CursorDef("CARNECONVE3", "SELECT TOP 1 [CarneId], [PeriodistaPremiado], [PeriodistaSueldo], [PeriodistaApellido], [PeriodistaNombre], [PeriodistaId] FROM [Periodista] WHERE [CarneId] = @CarneId ORDER BY [CarneId] ",false, GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK, false, this,prmCARNECONVE3,1,0,false,true )
             ,new CursorDef("CARNECONVE4", "INSERT INTO [GXA0003] ([CarneId], [PeriodistaId], [CarneNombre], [PeriodistaNombre], [PeriodistaApellido], [PeriodistaSueldo], [PeriodistaPremiado], [PeriodistaMonto]) VALUES (@AV2CarneId, @AV3PeriodistaId, @AV4CarneNombre, @AV5PeriodistaNombre, @AV6PeriodistaApellido, @AV7PeriodistaSueldo, @AV8PeriodistaPremiado, @AV9PeriodistaMonto)", GxErrorMask.GX_NOMASK,prmCARNECONVE4)
          };
       }
    }

    public void getResults( int cursor ,
                            IFieldGetter rslt ,
                            Object[] buf )
    {
       switch ( cursor )
       {
             case 0 :
                ((String[]) buf[0])[0] = rslt.getVarchar(1) ;
                ((short[]) buf[1])[0] = rslt.getShort(2) ;
                break;
             case 1 :
                ((short[]) buf[0])[0] = rslt.getShort(1) ;
                ((bool[]) buf[1])[0] = rslt.getBool(2) ;
                ((short[]) buf[2])[0] = rslt.getShort(3) ;
                ((String[]) buf[3])[0] = rslt.getVarchar(4) ;
                ((String[]) buf[4])[0] = rslt.getVarchar(5) ;
                ((short[]) buf[5])[0] = rslt.getShort(6) ;
                break;
       }
    }

    public void setParameters( int cursor ,
                               IFieldSetter stmt ,
                               Object[] parms )
    {
       switch ( cursor )
       {
             case 1 :
                stmt.SetParameter(1, (short)parms[0]);
                break;
             case 2 :
                stmt.SetParameter(1, (short)parms[0]);
                stmt.SetParameter(2, (short)parms[1]);
                stmt.SetParameter(3, (String)parms[2]);
                stmt.SetParameter(4, (String)parms[3]);
                stmt.SetParameter(5, (String)parms[4]);
                stmt.SetParameter(6, (short)parms[5]);
                stmt.SetParameter(7, (bool)parms[6]);
                stmt.SetParameter(8, (short)parms[7]);
                break;
       }
    }

 }

}
